<include file="../Public/_header.html" />
<div class="so_main">
  
  	<!-------- 搜索开始 -------->
		  <div id="search_div">
		  	<div class="page_tit">
		  		搜索文档 [ <a href="javascript:void(0);" onclick="_show_searcharea();">隐藏</a> ]
		  	</div>
		
				<div class="sform">
					<form method="post" action="{:U('/Global/document')}" id="searchForm">
						<input id="pno" name="pno" type="hidden" value="1">
							
					    <dl>
					      <span>文档类型：</span>
					      
						    	<input id="sortdesc" type="text" value="{$sort_id|getCategoryName}" 
					      					onclick="ui.box.load(
					    											'{:U('Index://Public/showtree',array('code'=>'document'))}'
					    											,{ title:'查看文档分类' })"
					      					readonly>
					      	<input id="sort_id" name="sort_id" type="hidden" value="{$sort_id}">
									<script>
											function _tmp_setselectdict(rel,txt){
									    		$('#sortdesc').val(txt);
									    		$('#sort_id').val(rel);
									    }
									</script>

					    	<span>&nbsp;&nbsp;&nbsp;</span>
					    	<input type="submit" class="btn_b" value="提交" />
					    </dl>
					</form>
			  </div>
		  </div>
		  <!-------- 搜索结束 -------->
  
  <div class="page_tit">文档管理</div>
  <div class="Toolbar_inbox">
	<a href="{:U('/Global/addDocument')}" class="btn_a""><span>添加文档</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteDocument();"><span>删除文档</span></a>
  </div>
  <div class="list">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">标题</th>
    <th class="line_l">分类</th>
    <th class="line_l">内容</th>
    <th class="line_l">创建</th>
    <th class="line_l">更新</th>
    <th class="line_l">是否有效</th>
    <th class="line_l">页脚显示</th>
	<th class="line_l">排序</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="pagedata['data']">
      <tr overstyle='on' id="{$vo.document_id}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.document_id}"></td>
        <td>{$vo.document_id}</td>
        <td>{$vo.title}</td>
        <td>{:getCategoryName($vo['sort_id'],'无分类')}</td>
        <php>$vo['content'] = real_strip_tags($vo['content']);</php>
        <td>{$vo.content|t|getShort=30}</td>
        <td>{$vo.author_id|getAdminName} {$vo.author_id|getAdminGroupIcon}<br/>{$vo.ctime|date="Y-m-d H:i",###}</td>
        <td>{$vo.last_editor_id|getAdminName} {$vo.last_editor_id|getAdminGroupIcon}<br/>{$vo.mtime|date="Y-m-d H:i",###}</td>
        <td><eq name="vo.is_active" value="1">是<else/>否</eq></td>
		<td><eq name="vo.is_on_footer" value="1">是<else/>否</eq></td>
        <td>
            <a href="javascript:void(0)" class="ico_top" onclick="move('{$vo['document_id']}','up');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="ico_btm" onclick="move('{$vo['document_id']}','down');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>
        </td>
        <td>
			<a href="{:U('/Global/editDocument',array('id'=>$vo['document_id']))}">编辑</a>
			<a href="javascript:void(0);" onclick="deleteDocument('{$vo.document_id}')">删除</a>
		</td>
      </tr>
  </volist>
  </table>
  </div>
  <div class="Toolbar_inbox">
	<div class="page_box">{$pagedata['html']}</div>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择用户的ID数组
    function getChecked() {
        var ids = new Array();
        $.each($('table input:checked'), function(i, n){
            ids.push( $(n).val() );
        });
        return ids;
    }
    
    function deleteDocument(ids) {
    	var length = 0;
    	if(ids) {
    		length = 1;
    	}else {
    		ids    = getChecked();
    		length = ids[0] == 0 ? ids.length - 1 : ids.length;
            ids    = ids.toString();
    	}
    	if(ids=='') {
    		ui.error('请先选择一篇文档');
    		return ;
    	}
    	if(confirm('您将删除'+length+'条文档，删除后无法恢复，确定继续？')) {
    		$.post("{:U('/Global/doDeleteDocument')}",{ids:ids},function(res){
    			if(res=='1') {
    				ui.success('删除成功');
    				removeItem(ids);
    			}else {
    				ui.error('删除失败');
    			}
    		});
    	}
    }
    
    function removeItem(ids) {
    	ids = ids.split(',');
        for(i = 0; i < ids.length; i++) {
            $('#'+ids[i]).remove();
        }
    }

	function move(document_id, direction) {
		var baseid  = direction == 'up' ? $('#'+document_id).prev().attr('id') : $('#'+document_id).next().attr('id');
		if(!baseid) {
			direction == 'up' ? ui.error('已经是最前面了') : ui.error('已经是最后面了');
		}else {
			$.post("{:U('/Global/doDocumentOrder')}", {document_id:document_id, baseid:baseid}, function(res){
				if(res == '1') {
					//交换位置
					direction == 'up' ? $('#'+document_id).insertBefore('#'+baseid) : $("#"+document_id).insertAfter('#'+baseid);
					ui.success('保存成功');
				}else {
					ui.error('保存失败');
				}
			});
		}
	}
</script>
<include file="../Public/_footer.html" />